package mymobile.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import mymobile.diagram.edit.parts.AppMobileAppSettingEditPart;
import mymobile.diagram.edit.parts.AppMobileEditPart;
import mymobile.diagram.edit.parts.AppMobileMainViewEditPart;
import mymobile.diagram.edit.parts.ContainerEditPart;
import mymobile.diagram.edit.parts.ImageEditPart;
import mymobile.diagram.edit.parts.InputEditPart;
import mymobile.diagram.edit.parts.LabelEditPart;
import mymobile.diagram.edit.parts.ListEditPart;
import mymobile.diagram.edit.parts.SettingEditPart;
import mymobile.diagram.edit.parts.ViewEditPart;
import mymobile.diagram.edit.parts.ViewNextViewsEditPart;
import mymobile.diagram.edit.parts.ViewViewComponentsEditPart;
import mymobile.diagram.edit.parts.ViewViewSettingEditPart;
import mymobile.diagram.part.MyMobileDiagramEditorPlugin;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class MyMobileElementTypes {

	/**
	 * @generated
	 */
	private MyMobileElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map<IElementType, ENamedElement> elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set<IElementType> KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Container_1000 = getElementType("MyMobile.diagram.Container_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType View_2005 = getElementType("MyMobile.diagram.View_2005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Input_2006 = getElementType("MyMobile.diagram.Input_2006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType List_2007 = getElementType("MyMobile.diagram.List_2007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AppMobile_2008 = getElementType("MyMobile.diagram.AppMobile_2008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Label_2009 = getElementType("MyMobile.diagram.Label_2009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Setting_2010 = getElementType("MyMobile.diagram.Setting_2010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Image_2011 = getElementType("MyMobile.diagram.Image_2011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AppMobileAppSetting_4003 = getElementType("MyMobile.diagram.AppMobileAppSetting_4003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ViewNextViews_4004 = getElementType("MyMobile.diagram.ViewNextViews_4004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ViewViewComponents_4002 = getElementType("MyMobile.diagram.ViewViewComponents_4002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AppMobileMainView_4005 = getElementType("MyMobile.diagram.AppMobileMainView_4005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ViewViewSetting_4001 = getElementType("MyMobile.diagram.ViewViewSetting_4001"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return MyMobileDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap<IElementType, ENamedElement>();

			elements.put(Container_1000,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getContainer());

			elements.put(View_2005,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE.getView());

			elements.put(Input_2006,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE.getInput());

			elements.put(List_2007,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE.getList());

			elements.put(AppMobile_2008,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getAppMobile());

			elements.put(Label_2009,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE.getLabel());

			elements.put(Setting_2010,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getSetting());

			elements.put(Image_2011,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE.getImage());

			elements.put(AppMobileAppSetting_4003,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getAppMobile_AppSetting());

			elements.put(ViewNextViews_4004,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getView_NextViews());

			elements.put(ViewViewComponents_4002,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getView_ViewComponents());

			elements.put(AppMobileMainView_4005,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getAppMobile_MainView());

			elements.put(ViewViewSetting_4001,
					mymobile.mobileTest.MobileTestPackage.eINSTANCE
							.getView_ViewSetting());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet<IElementType>();
			KNOWN_ELEMENT_TYPES.add(Container_1000);
			KNOWN_ELEMENT_TYPES.add(View_2005);
			KNOWN_ELEMENT_TYPES.add(Input_2006);
			KNOWN_ELEMENT_TYPES.add(List_2007);
			KNOWN_ELEMENT_TYPES.add(AppMobile_2008);
			KNOWN_ELEMENT_TYPES.add(Label_2009);
			KNOWN_ELEMENT_TYPES.add(Setting_2010);
			KNOWN_ELEMENT_TYPES.add(Image_2011);
			KNOWN_ELEMENT_TYPES.add(AppMobileAppSetting_4003);
			KNOWN_ELEMENT_TYPES.add(ViewNextViews_4004);
			KNOWN_ELEMENT_TYPES.add(ViewViewComponents_4002);
			KNOWN_ELEMENT_TYPES.add(AppMobileMainView_4005);
			KNOWN_ELEMENT_TYPES.add(ViewViewSetting_4001);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case ContainerEditPart.VISUAL_ID:
			return Container_1000;
		case ViewEditPart.VISUAL_ID:
			return View_2005;
		case InputEditPart.VISUAL_ID:
			return Input_2006;
		case ListEditPart.VISUAL_ID:
			return List_2007;
		case AppMobileEditPart.VISUAL_ID:
			return AppMobile_2008;
		case LabelEditPart.VISUAL_ID:
			return Label_2009;
		case SettingEditPart.VISUAL_ID:
			return Setting_2010;
		case ImageEditPart.VISUAL_ID:
			return Image_2011;
		case AppMobileAppSettingEditPart.VISUAL_ID:
			return AppMobileAppSetting_4003;
		case ViewNextViewsEditPart.VISUAL_ID:
			return ViewNextViews_4004;
		case ViewViewComponentsEditPart.VISUAL_ID:
			return ViewViewComponents_4002;
		case AppMobileMainViewEditPart.VISUAL_ID:
			return AppMobileMainView_4005;
		case ViewViewSettingEditPart.VISUAL_ID:
			return ViewViewSetting_4001;
		}
		return null;
	}

}
